/*
 * Copyright 2011 Kim Lindhardt Madsen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package dk.lindhardt.gwt.geie.client.evaluate;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * User: AnAmuser
 * Date: 28-08-11
 * <p/>
 * Range
 */
public class Range extends HashMap<Integer, HashMap<Integer, Serializable>> implements Serializable {

   public Range() {
      super();
   }

   public Range(HashMap<Integer, HashMap<Integer, Serializable>> range) {
      super(range);
   }

   public void setValue(int row, int column, Serializable value) {
      HashMap<Integer, Serializable> rowMap = get(row);
      if (rowMap == null) {
         rowMap = new HashMap<Integer, Serializable>();
         put(row, rowMap);
      }
      rowMap.put(column, value);
   }

   public List<Serializable> getValues() {
      List<Serializable> result = new ArrayList<Serializable>();
      for (Integer row : keySet()) {
         HashMap<Integer, Serializable> rowMap = get(row);
         for (Integer column : rowMap.keySet()) {
            result.add(rowMap.get(column));
         }
      }
      return result;
   }

}
